package cn.achao.csr.base.utils;

import cn.achao.csr.base.constant.enums.SysSourceEnum;
import cn.achao.csr.base.exception.BusinessException;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * ip 工具类
 * @Author: achao
 **/
public class IpUtils {

    /**
     * 获取当前服务的ip地址
     */
    public static String getCurrentServerIP() {
        try {
            InetAddress inetAddress = InetAddress.getLocalHost();
            return inetAddress.getHostAddress();
        } catch (UnknownHostException e) {
            ThrowUtils.throwIf(BusinessException.fail("获取当前服务的ip地址失败", SysSourceEnum.CSR_SYSTEM.getSysName()));
        }
        return null;
    }
}
